home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / gcc / gcc261a.zoo / info / gcc.info-7 < prev    next >
Encoding:
GNU Info File  |  1994-10-31  |  49.6 KB  |  1,286 lines

  1. This is Info file gcc.info, produced by Makeinfo-1.54 from the input
  2. file gcc.texi.
  3.  
  4.    This file documents the use and the internals of the GNU compiler.
  5.  
  6.    Published by the Free Software Foundation 675 Massachusetts Avenue
  7. Cambridge, MA 02139 USA
  8.  
  9.    Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
  10.  
  11.    Permission is granted to make and distribute verbatim copies of this
  12. manual provided the copyright notice and this permission notice are
  13. preserved on all copies.
  14.  
  15.    Permission is granted to copy and distribute modified versions of
  16. this manual under the conditions for verbatim copying, provided also
  17. that the sections entitled "GNU General Public License" and "Protect
  18. Your Freedom--Fight `Look And Feel'" are included exactly as in the
  19. original, and provided that the entire resulting derived work is
  20. distributed under the terms of a permission notice identical to this
  21. one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that the sections entitled "GNU General Public
  26. License" and "Protect Your Freedom--Fight `Look And Feel'", and this
  27. permission notice, may be included in translations approved by the Free
  28. Software Foundation instead of in the original English.
  29.  
  30. File: gcc.info,  Node: VMS Install,  Next: Collect2,  Prev: Sun Install,  Up: Installation
  31.  
  32. Installing GNU CC on VMS
  33. ========================
  34.  
  35.    The VMS version of GNU CC is distributed in a backup saveset
  36. containing both source code and precompiled binaries.
  37.  
  38.    To install the `gcc' command so you can use the compiler easily, in
  39. the same manner as you use the VMS C compiler, you must install the VMS
  40. CLD file for GNU CC as follows:
  41.  
  42.   1. Define the VMS logical names `GNU_CC' and `GNU_CC_INCLUDE' to
  43.      point to the directories where the GNU CC executables
  44.      (`gcc-cpp.exe', `gcc-cc1.exe', etc.) and the C include files are
  45.      kept respectively.  This should be done with the commands:
  46.  
  47.           $ assign /system /translation=concealed -
  48.             disk:[gcc.] gnu_cc
  49.           $ assign /system /translation=concealed -
  50.             disk:[gcc.include.] gnu_cc_include
  51.  
  52.      with the appropriate disk and directory names.  These commands can
  53.      be placed in your system startup file so they will be executed
  54.      whenever the machine is rebooted.  You may, if you choose, do this
  55.      via the `GCC_INSTALL.COM' script in the `[GCC]' directory.
  56.  
  57.   2. Install the `GCC' command with the command line:
  58.  
  59.           $ set command /table=sys$common:[syslib]dcltables -
  60.             /output=sys$common:[syslib]dcltables gnu_cc:[000000]gcc
  61.           $ install replace sys$common:[syslib]dcltables
  62.  
  63.   3. To install the help file, do the following:
  64.  
  65.           $ library/help sys$library:helplib.hlb gcc.hlp
  66.  
  67.      Now you can invoke the compiler with a command like `gcc /verbose
  68.      file.c', which is equivalent to the command `gcc -v -c file.c' in
  69.      Unix.
  70.  
  71.    If you wish to use GNU C++ you must first install GNU CC, and then
  72. perform the following steps:
  73.  
  74.   1. Define the VMS logical name `GNU_GXX_INCLUDE' to point to the
  75.      directory where the preprocessor will search for the C++ header
  76.      files.  This can be done with the command:
  77.  
  78.           $ assign /system /translation=concealed -
  79.             disk:[gcc.gxx_include.] gnu_gxx_include
  80.  
  81.      with the appropriate disk and directory name.  If you are going to
  82.      be using libg++, this is where the libg++ install procedure will
  83.      install the libg++ header files.
  84.  
  85.   2. Obtain the file `gcc-cc1plus.exe', and place this in the same
  86.      directory that `gcc-cc1.exe' is kept.
  87.  
  88.      The GNU C++ compiler can be invoked with a command like `gcc /plus
  89.      /verbose file.cc', which is equivalent to the command `g++ -v -c
  90.      file.cc' in Unix.
  91.  
  92.    We try to put corresponding binaries and sources on the VMS
  93. distribution tape.  But sometimes the binaries will be from an older
  94. version than the sources, because we don't always have time to update
  95. them.  (Use the `/version' option to determine the version number of
  96. the binaries and compare it with the source file `version.c' to tell
  97. whether this is so.)  In this case, you should use the binaries you get
  98. to recompile the sources.  If you must recompile, here is how:
  99.  
  100.   1. Execute the command procedure `vmsconfig.com' to set up the files
  101.      `tm.h', `config.h', `aux-output.c', and `md.', and to create files
  102.      `tconfig.h' and `hconfig.h'.  This procedure also creates several
  103.      linker option files used by `make-cc1.com' and a data file used by
  104.      `make-l2.com'.
  105.  
  106.           $ @vmsconfig.com
  107.  
  108.   2. Setup the logical names and command tables as defined above.  In
  109.      addition, define the VMS logical name `GNU_BISON' to point at the
  110.      to the directories where the Bison executable is kept.  This
  111.      should be done with the command:
  112.  
  113.           $ assign /system /translation=concealed -
  114.             disk:[bison.] gnu_bison
  115.  
  116.      You may, if you choose, use the `INSTALL_BISON.COM' script in the
  117.      `[BISON]' directory.
  118.  
  119.   3. Install the `BISON' command with the command line:
  120.  
  121.           $ set command /table=sys$common:[syslib]dcltables -
  122.             /output=sys$common:[syslib]dcltables -
  123.             gnu_bison:[000000]bison
  124.           $ install replace sys$common:[syslib]dcltables
  125.  
  126.   4. Type `@make-gcc' to recompile everything (alternatively, submit
  127.      the file `make-gcc.com' to a batch queue).  If you wish to build
  128.      the GNU C++ compiler as well as the GNU CC compiler, you must
  129.      first edit `make-gcc.com' and follow the instructions that appear
  130.      in the comments.
  131.  
  132.   5. In order to use GCC, you need a library of functions which GCC
  133.      compiled code will call to perform certain tasks, and these
  134.      functions are defined in the file `libgcc2.c'.  To compile this
  135.      you should use the command procedure `make-l2.com', which will
  136.      generate the library `libgcc2.olb'.  `libgcc2.olb' should be built
  137.      using the compiler built from the same distribution that
  138.      `libgcc2.c' came from, and `make-gcc.com' will automatically do
  139.      all of this for you.
  140.  
  141.      To install the library, use the following commands:
  142.  
  143.           $ library gnu_cc:[000000]gcclib/delete=(new,eprintf)
  144.           $ library gnu_cc:[000000]gcclib/delete=L_*
  145.           $ library libgcc2/extract=*/output=libgcc2.obj
  146.           $ library gnu_cc:[000000]gcclib libgcc2.obj
  147.  
  148.      The first command simply removes old modules that will be replaced
  149.      with modules from `libgcc2' under different module names.  The
  150.      modules `new' and `eprintf' may not actually be present in your
  151.      `gcclib.olb'--if the VMS librarian complains about those modules
  152.      not being present, simply ignore the message and continue on with
  153.      the next command.  The second command removes the modules that
  154.      came from the previous version of the library `libgcc2.c'.
  155.  
  156.      Whenever you update the compiler on your system, you should also
  157.      update the library with the above procedure.
  158.  
  159.   6. You may wish to build GCC in such a way that no files are written
  160.      to the directory where the source files reside.  An example would
  161.      be the when the source files are on a read-only disk.  In these
  162.      cases, execute the following DCL commands (substituting your
  163.      actual path names):
  164.  
  165.           $ assign dua0:[gcc.build_dir.]/translation=concealed, -
  166.                    dua1:[gcc.source_dir.]/translation=concealed  gcc_build
  167.           $ set default gcc_build:[000000]
  168.  
  169.      where the directory `dua1:[gcc.source_dir]' contains the source
  170.      code, and the directory `dua0:[gcc.build_dir]' is meant to contain
  171.      all of the generated object files and executables.  Once you have
  172.      done this, you can proceed building GCC as described above.  (Keep
  173.      in mind that `gcc_build' is a rooted logical name, and thus the
  174.      device names in each element of the search list must be an actual
  175.      physical device name rather than another rooted logical name).
  176.  
  177.   7. *If you are building GNU CC with a previous version of GNU CC, you
  178.      also should check to see that you have the newest version of the
  179.      assembler*.  In particular, GNU CC version 2 treats global constant
  180.      variables slightly differently from GNU CC version 1, and GAS
  181.      version 1.38.1 does not have the patches required to work with GCC
  182.      version 2.  If you use GAS 1.38.1, then `extern const' variables
  183.      will not have the read-only bit set, and the linker will generate
  184.      warning messages about mismatched psect attributes for these
  185.      variables.  These warning messages are merely a nuisance, and can
  186.      safely be ignored.
  187.  
  188.      If you are compiling with a version of GNU CC older than 1.33,
  189.      specify `/DEFINE=("inline=")' as an option in all the
  190.      compilations.  This requires editing all the `gcc' commands in
  191.      `make-cc1.com'.  (The older versions had problems supporting
  192.      `inline'.)  Once you have a working 1.33 or newer GNU CC, you can
  193.      change this file back.
  194.  
  195.   8. If you want to build GNU CC with the VAX C compiler, you will need
  196.      to make minor changes in `make-cccp.com' and `make-cc1.com' to
  197.      choose alternate definitions of `CC', `CFLAGS', and `LIBS'.  See
  198.      comments in those files.  However, you must also have a working
  199.      version of the GNU assembler (GNU as, aka GAS) as it is used as
  200.      the back-end for GNU CC to produce binary object modules and is
  201.      not included in the GNU CC sources.  GAS is also needed to compile
  202.      `libgcc2' in order to build `gcclib' (see above); `make-l2.com'
  203.      expects to be able to find it operational in
  204.      `gnu_cc:[000000]gnu-as.exe'.
  205.  
  206.      To use GNU CC on VMS, you need the VMS driver programs `gcc.exe',
  207.      `gcc.com', and `gcc.cld'.  They are distributed with the VMS
  208.      binaries (`gcc-vms') rather than the GNU CC sources.  GAS is also
  209.      included in `gcc-vms', as is Bison.
  210.  
  211.      Once you have successfully built GNU CC with VAX C, you should use
  212.      the resulting compiler to rebuild itself.  Before doing this, be
  213.      sure to restore the `CC', `CFLAGS', and `LIBS' definitions in
  214.      `make-cccp.com' and `make-cc1.com'.  The second generation
  215.      compiler will be able to take advantage of many optimizations that
  216.      must be suppressed when building with other compilers.
  217.  
  218.    Under previous versions of GNU CC, the generated code would
  219. occasionally give strange results when linked with the sharable
  220. `VAXCRTL' library.  Now this should work.
  221.  
  222.    Even with this version, however, GNU CC itself should not be linked
  223. with the sharable `VAXCRTL'.  The version of `qsort' in `VAXCRTL' has a
  224. bug (known to be present in VMS versions V4.6 through V5.5) which
  225. causes the compiler to fail.
  226.  
  227.    The executables are generated by `make-cc1.com' and `make-cccp.com'
  228. use the object library version of `VAXCRTL' in order to make use of the
  229. `qsort' routine in `gcclib.olb'.  If you wish to link the compiler
  230. executables with the shareable image version of `VAXCRTL', you should
  231. edit the file `tm.h' (created by `vmsconfig.com') to define the macro
  232. `QSORT_WORKAROUND'.
  233.  
  234.    `QSORT_WORKAROUND' is always defined when GNU CC is compiled with
  235. VAX C, to avoid a problem in case `gcclib.olb' is not yet available.
  236.  
  237. File: gcc.info,  Node: Collect2,  Next: Header Dirs,  Prev: VMS Install,  Up: Installation
  238.  
  239. `collect2'
  240. ==========
  241.  
  242.    Many target systems do not have support in the assembler and linker
  243. for "constructors"--initialization functions to be called before the
  244. official "start" of `main'.  On such systems, GNU CC uses a utility
  245. called `collect2' to arrange to call these functions at start time.
  246.  
  247.    The program `collect2' works by linking the program once and looking
  248. through the linker output file for symbols with particular names
  249. indicating they are constructor functions.  If it finds any, it creates
  250. a new temporary `.c' file containing a table of them, compiles it, and
  251. links the program a second time including that file.
  252.  
  253.    The actual calls to the constructors are carried out by a subroutine
  254. called `__main', which is called (automatically) at the beginning of
  255. the body of `main' (provided `main' was compiled with GNU CC).  Calling
  256. `__main' is necessary, even when compiling C code, to allow linking C
  257. and C++ object code together.  (If you use `-nostdlib', you get an
  258. unresolved reference to `__main', since it's defined in the standard
  259. GCC library.  Include `-lgcc' at the end of your compiler command line
  260. to resolve this reference.)
  261.  
  262.    The program `collect2' is installed as `ld' in the directory where
  263. the passes of the compiler are installed.  When `collect2' needs to
  264. find the *real* `ld', it tries the following file names:
  265.  
  266.    * `real-ld' in the directories listed in the compiler's search
  267.      directories.
  268.  
  269.    * `real-ld' in the directories listed in the environment variable
  270.      `PATH'.
  271.  
  272.    * The file specified in the `REAL_LD_FILE_NAME' configuration macro,
  273.      if specified.
  274.  
  275.    * `ld' in the compiler's search directories, except that `collect2'
  276.      will not execute itself recursively.
  277.  
  278.    * `ld' in `PATH'.
  279.  
  280.    "The compiler's search directories" means all the directories where
  281. `gcc' searches for passes of the compiler.  This includes directories
  282. that you specify with `-B'.
  283.  
  284.    Cross-compilers search a little differently:
  285.  
  286.    * `real-ld' in the compiler's search directories.
  287.  
  288.    * `TARGET-real-ld' in `PATH'.
  289.  
  290.    * The file specified in the `REAL_LD_FILE_NAME' configuration macro,
  291.      if specified.
  292.  
  293.    * `ld' in the compiler's search directories.
  294.  
  295.    * `TARGET-ld' in `PATH'.
  296.  
  297.    `collect2' explicitly avoids running `ld' using the file name under
  298. which `collect2' itself was invoked.  In fact, it remembers up a list
  299. of such names--in case one copy of `collect2' finds another copy (or
  300. version) of `collect2' installed as `ld' in a second place in the
  301. search path.
  302.  
  303.    `collect2' searches for the utilities `nm' and `strip' using the
  304. same algorithm as above for `ld'.
  305.  
  306. File: gcc.info,  Node: Header Dirs,  Prev: Collect2,  Up: Installation
  307.  
  308. Standard Header File Directories
  309. ================================
  310.  
  311.    `GCC_INCLUDE_DIR' means the same thing for native and cross.  It is
  312. where GNU CC stores its private include files, and also where GNU CC
  313. stores the fixed include files.  A cross compiled GNU CC runs
  314. `fixincludes' on the header files in `$(tooldir)/include'.  (If the
  315. cross compilation header files need to be fixed, they must be installed
  316. before GNU CC is built.  If the cross compilation header files are
  317. already suitable for ANSI C and GNU CC, nothing special need be done).
  318.  
  319.    `GPLUS_INCLUDE_DIR' means the same thing for native and cross.  It
  320. is where `g++' looks first for header files.  `libg++' installs only
  321. target independent header files in that directory.
  322.  
  323.    `LOCAL_INCLUDE_DIR' is used only for a native compiler.  It is
  324. normally `/usr/local/include'.  GNU CC searches this directory so that
  325. users can install header files in `/usr/local/include'.
  326.  
  327.    `CROSS_INCLUDE_DIR' is used only for a cross compiler.  GNU CC
  328. doesn't install anything there.
  329.  
  330.    `TOOL_INCLUDE_DIR' is used for both native and cross compilers.  It
  331. is the place for other packages to install header files that GNU CC will
  332. use.  For a cross-compiler, this is the equivalent of `/usr/include'.
  333. When you build a cross-compiler, `fixincludes' processes any header
  334. files in this directory.
  335.  
  336. File: gcc.info,  Node: C Extensions,  Next: C++ Extensions,  Prev: Installation,  Up: Top
  337.  
  338. Extensions to the C Language Family
  339. ***********************************
  340.  
  341.    GNU C provides several language features not found in ANSI standard
  342. C.  (The `-pedantic' option directs GNU CC to print a warning message if
  343. any of these features is used.)  To test for the availability of these
  344. features in conditional compilation, check for a predefined macro
  345. `__GNUC__', which is always defined under GNU CC.
  346.  
  347.    These extensions are available in C and in the languages derived from
  348. it, C++ and Objective C.  *Note Extensions to the C++ Language: C++
  349. Extensions, for extensions that apply *only* to C++.
  350.  
  351. * Menu:
  352.  
  353. * Statement Exprs::     Putting statements and declarations inside expressions.
  354. * Local Labels::        Labels local to a statement-expression.
  355. * Labels as Values::    Getting pointers to labels, and computed gotos.
  356. * Nested Functions::    As in Algol and Pascal, lexical scoping of functions.
  357. * Constructing Calls::    Dispatching a call to another function.
  358. * Naming Types::        Giving a name to the type of some expression.
  359. * Typeof::              `typeof': referring to the type of an expression.
  360. * Lvalues::             Using `?:', `,' and casts in lvalues.
  361. * Conditionals::        Omitting the middle operand of a `?:' expression.
  362. * Long Long::        Double-word integers--`long long int'.
  363. * Complex::             Data types for complex numbers.
  364. * Zero Length::         Zero-length arrays.
  365. * Variable Length::     Arrays whose length is computed at run time.
  366. * Macro Varargs::    Macros with variable number of arguments.
  367. * Subscripting::        Any array can be subscripted, even if not an lvalue.
  368. * Pointer Arith::       Arithmetic on `void'-pointers and function pointers.
  369. * Initializers::        Non-constant initializers.
  370. * Constructors::        Constructor expressions give structures, unions
  371.                          or arrays as values.
  372. * Labeled Elements::    Labeling elements of initializers.
  373. * Cast to Union::       Casting to union type from any member of the union.
  374. * Case Ranges::        `case 1 ... 9' and such.
  375. * Function Attributes:: Declaring that functions have no side effects,
  376.                          or that they can never return.
  377. * Function Prototypes:: Prototype declarations and old-style definitions.
  378. * Dollar Signs::        Dollar sign is allowed in identifiers.
  379. * Character Escapes::   `\e' stands for the character ESC.
  380. * Variable Attributes::    Specifying attributes of variables.
  381. * Alignment::           Inquiring about the alignment of a type or variable.
  382. * Inline::              Defining inline functions (as fast as macros).
  383. * Extended Asm::        Assembler instructions with C expressions as operands.
  384.                          (With them you can define "built-in" functions.)
  385. * Asm Labels::          Specifying the assembler name to use for a C symbol.
  386. * Explicit Reg Vars::   Defining variables residing in specified registers.
  387. * Alternate Keywords::  `__const__', `__asm__', etc., for header files.
  388. * Incomplete Enums::    `enum foo;', with details to follow.
  389. * Function Names::    Printable strings which are the name of the current
  390.              function.
  391.  
  392. File: gcc.info,  Node: Statement Exprs,  Next: Local Labels,  Up: C Extensions
  393.  
  394. Statements and Declarations in Expressions
  395. ==========================================
  396.  
  397.    A compound statement enclosed in parentheses may appear as an
  398. expression in GNU C.  This allows you to use loops, switches, and local
  399. variables within an expression.
  400.  
  401.    Recall that a compound statement is a sequence of statements
  402. surrounded by braces; in this construct, parentheses go around the
  403. braces.  For example:
  404.  
  405.      ({ int y = foo (); int z;
  406.         if (y > 0) z = y;
  407.         else z = - y;
  408.         z; })
  409.  
  410. is a valid (though slightly more complex than necessary) expression for
  411. the absolute value of `foo ()'.
  412.  
  413.    The last thing in the compound statement should be an expression
  414. followed by a semicolon; the value of this subexpression serves as the
  415. value of the entire construct.  (If you use some other kind of statement
  416. last within the braces, the construct has type `void', and thus
  417. effectively no value.)
  418.  
  419.    This feature is especially useful in making macro definitions "safe"
  420. (so that they evaluate each operand exactly once).  For example, the
  421. "maximum" function is commonly defined as a macro in standard C as
  422. follows:
  423.  
  424.      #define max(a,b) ((a) > (b) ? (a) : (b))
  425.  
  426. But this definition computes either A or B twice, with bad results if
  427. the operand has side effects.  In GNU C, if you know the type of the
  428. operands (here let's assume `int'), you can define the macro safely as
  429. follows:
  430.  
  431.      #define maxint(a,b) \
  432.        ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
  433.  
  434.    Embedded statements are not allowed in constant expressions, such as
  435. the value of an enumeration constant, the width of a bit field, or the
  436. initial value of a static variable.
  437.  
  438.    If you don't know the type of the operand, you can still do this,
  439. but you must use `typeof' (*note Typeof::.) or type naming (*note
  440. Naming Types::.).
  441.  
  442. File: gcc.info,  Node: Local Labels,  Next: Labels as Values,  Prev: Statement Exprs,  Up: C Extensions
  443.  
  444. Locally Declared Labels
  445. =======================
  446.  
  447.    Each statement expression is a scope in which "local labels" can be
  448. declared.  A local label is simply an identifier; you can jump to it
  449. with an ordinary `goto' statement, but only from within the statement
  450. expression it belongs to.
  451.  
  452.    A local label declaration looks like this:
  453.  
  454.      __label__ LABEL;
  455.  
  456. or
  457.  
  458.      __label__ LABEL1, LABEL2, ...;
  459.  
  460.    Local label declarations must come at the beginning of the statement
  461. expression, right after the `({', before any ordinary declarations.
  462.  
  463.    The label declaration defines the label *name*, but does not define
  464. the label itself.  You must do this in the usual way, with `LABEL:',
  465. within the statements of the statement expression.
  466.  
  467.    The local label feature is useful because statement expressions are
  468. often used in macros.  If the macro contains nested loops, a `goto' can
  469. be useful for breaking out of them.  However, an ordinary label whose
  470. scope is the whole function cannot be used: if the macro can be
  471. expanded several times in one function, the label will be multiply
  472. defined in that function.  A local label avoids this problem.  For
  473. example:
  474.  
  475.      #define SEARCH(array, target)                     \
  476.      ({                                               \
  477.        __label__ found;                                \
  478.        typeof (target) _SEARCH_target = (target);      \
  479.        typeof (*(array)) *_SEARCH_array = (array);     \
  480.        int i, j;                                       \
  481.        int value;                                      \
  482.        for (i = 0; i < max; i++)                       \
  483.          for (j = 0; j < max; j++)                     \
  484.            if (_SEARCH_array[i][j] == _SEARCH_target)  \
  485.              { value = i; goto found; }              \
  486.        value = -1;                                     \
  487.       found:                                           \
  488.        value;                                          \
  489.      })
  490.  
  491. File: gcc.info,  Node: Labels as Values,  Next: Nested Functions,  Prev: Local Labels,  Up: C Extensions
  492.  
  493. Labels as Values
  494. ================
  495.  
  496.    You can get the address of a label defined in the current function
  497. (or a containing function) with the unary operator `&&'.  The value has
  498. type `void *'.  This value is a constant and can be used wherever a
  499. constant of that type is valid.  For example:
  500.  
  501.      void *ptr;
  502.      ...
  503.      ptr = &&foo;
  504.  
  505.    To use these values, you need to be able to jump to one.  This is
  506. done with the computed goto statement(1), `goto *EXP;'.  For example,
  507.  
  508.      goto *ptr;
  509.  
  510. Any expression of type `void *' is allowed.
  511.  
  512.    One way of using these constants is in initializing a static array
  513. that will serve as a jump table:
  514.  
  515.      static void *array[] = { &&foo, &&bar, &&hack };
  516.  
  517.    Then you can select a label with indexing, like this:
  518.  
  519.      goto *array[i];
  520.  
  521. Note that this does not check whether the subscript is in bounds--array
  522. indexing in C never does that.
  523.  
  524.    Such an array of label values serves a purpose much like that of the
  525. `switch' statement.  The `switch' statement is cleaner, so use that
  526. rather than an array unless the problem does not fit a `switch'
  527. statement very well.
  528.  
  529.    Another use of label values is in an interpreter for threaded code.
  530. The labels within the interpreter function can be stored in the
  531. threaded code for super-fast dispatching.
  532.  
  533.    You can use this mechanism to jump to code in a different function.
  534. If you do that, totally unpredictable things will happen.  The best way
  535. to avoid this is to store the label address only in automatic variables
  536. and never pass it as an argument.
  537.  
  538.    ---------- Footnotes ----------
  539.  
  540.    (1)  The analogous feature in Fortran is called an assigned goto,
  541. but that name seems inappropriate in C, where one can do more than
  542. simply store label addresses in label variables.
  543.  
  544. File: gcc.info,  Node: Nested Functions,  Next: Constructing Calls,  Prev: Labels as Values,  Up: C Extensions
  545.  
  546. Nested Functions
  547. ================
  548.  
  549.    A "nested function" is a function defined inside another function.
  550. (Nested functions are not supported for GNU C++.)  The nested function's
  551. name is local to the block where it is defined.  For example, here we
  552. define a nested function named `square', and call it twice:
  553.  
  554.      foo (double a, double b)
  555.      {
  556.        double square (double z) { return z * z; }
  557.      
  558.        return square (a) + square (b);
  559.      }
  560.  
  561.    The nested function can access all the variables of the containing
  562. function that are visible at the point of its definition.  This is
  563. called "lexical scoping".  For example, here we show a nested function
  564. which uses an inherited variable named `offset':
  565.  
  566.      bar (int *array, int offset, int size)
  567.      {
  568.        int access (int *array, int index)
  569.          { return array[index + offset]; }
  570.        int i;
  571.        ...
  572.        for (i = 0; i < size; i++)
  573.          ... access (array, i) ...
  574.      }
  575.  
  576.    Nested function definitions are permitted within functions in the
  577. places where variable definitions are allowed; that is, in any block,
  578. before the first statement in the block.
  579.  
  580.    It is possible to call the nested function from outside the scope of
  581. its name by storing its address or passing the address to another
  582. function:
  583.  
  584.      hack (int *array, int size)
  585.      {
  586.        void store (int index, int value)
  587.          { array[index] = value; }
  588.      
  589.        intermediate (store, size);
  590.      }
  591.  
  592.    Here, the function `intermediate' receives the address of `store' as
  593. an argument.  If `intermediate' calls `store', the arguments given to
  594. `store' are used to store into `array'.  But this technique works only
  595. so long as the containing function (`hack', in this example) does not
  596. exit.
  597.  
  598.    If you try to call the nested function through its address after the
  599. containing function has exited, all hell will break loose.  If you try
  600. to call it after a containing scope level has exited, and if it refers
  601. to some of the variables that are no longer in scope, you may be lucky,
  602. but it's not wise to take the risk.  If, however, the nested function
  603. does not refer to anything that has gone out of scope, you should be
  604. safe.
  605.  
  606.    GNU CC implements taking the address of a nested function using a
  607. technique called "trampolines".  A paper describing them is available
  608. from `maya.idiap.ch' in directory `pub/tmb', file `usenix88-lexic.ps.Z'.
  609.  
  610.    A nested function can jump to a label inherited from a containing
  611. function, provided the label was explicitly declared in the containing
  612. function (*note Local Labels::.).  Such a jump returns instantly to the
  613. containing function, exiting the nested function which did the `goto'
  614. and any intermediate functions as well.  Here is an example:
  615.  
  616.      bar (int *array, int offset, int size)
  617.      {
  618.        __label__ failure;
  619.        int access (int *array, int index)
  620.          {
  621.            if (index > size)
  622.              goto failure;
  623.            return array[index + offset];
  624.          }
  625.        int i;
  626.        ...
  627.        for (i = 0; i < size; i++)
  628.          ... access (array, i) ...
  629.        ...
  630.        return 0;
  631.      
  632.       /* Control comes here from `access'
  633.          if it detects an error.  */
  634.       failure:
  635.        return -1;
  636.      }
  637.  
  638.    A nested function always has internal linkage.  Declaring one with
  639. `extern' is erroneous.  If you need to declare the nested function
  640. before its definition, use `auto' (which is otherwise meaningless for
  641. function declarations).
  642.  
  643.      bar (int *array, int offset, int size)
  644.      {
  645.        __label__ failure;
  646.        auto int access (int *, int);
  647.        ...
  648.        int access (int *array, int index)
  649.          {
  650.            if (index > size)
  651.              goto failure;
  652.            return array[index + offset];
  653.          }
  654.        ...
  655.      }
  656.  
  657. File: gcc.info,  Node: Constructing Calls,  Next: Naming Types,  Prev: Nested Functions,  Up: C Extensions
  658.  
  659. Constructing Function Calls
  660. ===========================
  661.  
  662.    Using the built-in functions described below, you can record the
  663. arguments a function received, and call another function with the same
  664. arguments, without knowing the number or types of the arguments.
  665.  
  666.    You can also record the return value of that function call, and
  667. later return that value, without knowing what data type the function
  668. tried to return (as long as your caller expects that data type).
  669.  
  670. `__builtin_apply_args ()'
  671.      This built-in function returns a pointer of type `void *' to data
  672.      describing how to perform a call with the same arguments as were
  673.      passed to the current function.
  674.  
  675.      The function saves the arg pointer register, structure value
  676.      address, and all registers that might be used to pass arguments to
  677.      a function into a block of memory allocated on the stack.  Then it
  678.      returns the address of that block.
  679.  
  680. `__builtin_apply (FUNCTION, ARGUMENTS, SIZE)'
  681.      This built-in function invokes FUNCTION (type `void (*)()') with a
  682.      copy of the parameters described by ARGUMENTS (type `void *') and
  683.      SIZE (type `int').
  684.  
  685.      The value of ARGUMENTS should be the value returned by
  686.      `__builtin_apply_args'.  The argument SIZE specifies the size of
  687.      the stack argument data, in bytes.
  688.  
  689.      This function returns a pointer of type `void *' to data describing
  690.      how to return whatever value was returned by FUNCTION.  The data
  691.      is saved in a block of memory allocated on the stack.
  692.  
  693.      It is not always simple to compute the proper value for SIZE.  The
  694.      value is used by `__builtin_apply' to compute the amount of data
  695.      that should be pushed on the stack and copied from the incoming
  696.      argument area.
  697.  
  698. `__builtin_return (RESULT)'
  699.      This built-in function returns the value described by RESULT from
  700.      the containing function.  You should specify, for RESULT, a value
  701.      returned by `__builtin_apply'.
  702.  
  703. File: gcc.info,  Node: Naming Types,  Next: Typeof,  Prev: Constructing Calls,  Up: C Extensions
  704.  
  705. Naming an Expression's Type
  706. ===========================
  707.  
  708.    You can give a name to the type of an expression using a `typedef'
  709. declaration with an initializer.  Here is how to define NAME as a type
  710. name for the type of EXP:
  711.  
  712.      typedef NAME = EXP;
  713.  
  714.    This is useful in conjunction with the statements-within-expressions
  715. feature.  Here is how the two together can be used to define a safe
  716. "maximum" macro that operates on any arithmetic type:
  717.  
  718.      #define max(a,b) \
  719.        ({typedef _ta = (a), _tb = (b);  \
  720.          _ta _a = (a); _tb _b = (b);     \
  721.          _a > _b ? _a : _b; })
  722.  
  723.    The reason for using names that start with underscores for the local
  724. variables is to avoid conflicts with variable names that occur within
  725. the expressions that are substituted for `a' and `b'.  Eventually we
  726. hope to design a new form of declaration syntax that allows you to
  727. declare variables whose scopes start only after their initializers;
  728. this will be a more reliable way to prevent such conflicts.
  729.  
  730. File: gcc.info,  Node: Typeof,  Next: Lvalues,  Prev: Naming Types,  Up: C Extensions
  731.  
  732. Referring to a Type with `typeof'
  733. =================================
  734.  
  735.    Another way to refer to the type of an expression is with `typeof'.
  736. The syntax of using of this keyword looks like `sizeof', but the
  737. construct acts semantically like a type name defined with `typedef'.
  738.  
  739.    There are two ways of writing the argument to `typeof': with an
  740. expression or with a type.  Here is an example with an expression:
  741.  
  742.      typeof (x[0](1))
  743.  
  744. This assumes that `x' is an array of functions; the type described is
  745. that of the values of the functions.
  746.  
  747.    Here is an example with a typename as the argument:
  748.  
  749.      typeof (int *)
  750.  
  751. Here the type described is that of pointers to `int'.
  752.  
  753.    If you are writing a header file that must work when included in
  754. ANSI C programs, write `__typeof__' instead of `typeof'.  *Note
  755. Alternate Keywords::.
  756.  
  757.    A `typeof'-construct can be used anywhere a typedef name could be
  758. used.  For example, you can use it in a declaration, in a cast, or
  759. inside of `sizeof' or `typeof'.
  760.  
  761.    * This declares `y' with the type of what `x' points to.
  762.  
  763.           typeof (*x) y;
  764.  
  765.    * This declares `y' as an array of such values.
  766.  
  767.           typeof (*x) y[4];
  768.  
  769.    * This declares `y' as an array of pointers to characters:
  770.  
  771.           typeof (typeof (char *)[4]) y;
  772.  
  773.      It is equivalent to the following traditional C declaration:
  774.  
  775.           char *y[4];
  776.  
  777.      To see the meaning of the declaration using `typeof', and why it
  778.      might be a useful way to write, let's rewrite it with these macros:
  779.  
  780.           #define pointer(T)  typeof(T *)
  781.           #define array(T, N) typeof(T [N])
  782.  
  783.      Now the declaration can be rewritten this way:
  784.  
  785.           array (pointer (char), 4) y;
  786.  
  787.      Thus, `array (pointer (char), 4)' is the type of arrays of 4
  788.      pointers to `char'.
  789.  
  790. File: gcc.info,  Node: Lvalues,  Next: Conditionals,  Prev: Typeof,  Up: C Extensions
  791.  
  792. Generalized Lvalues
  793. ===================
  794.  
  795.    Compound expressions, conditional expressions and casts are allowed
  796. as lvalues provided their operands are lvalues.  This means that you
  797. can take their addresses or store values into them.
  798.  
  799.    For example, a compound expression can be assigned, provided the last
  800. expression in the sequence is an lvalue.  These two expressions are
  801. equivalent:
  802.  
  803.      (a, b) += 5
  804.      a, (b += 5)
  805.  
  806.    Similarly, the address of the compound expression can be taken.
  807. These two expressions are equivalent:
  808.  
  809.      &(a, b)
  810.      a, &b
  811.  
  812.    A conditional expression is a valid lvalue if its type is not void
  813. and the true and false branches are both valid lvalues.  For example,
  814. these two expressions are equivalent:
  815.  
  816.      (a ? b : c) = 5
  817.      (a ? b = 5 : (c = 5))
  818.  
  819.    A cast is a valid lvalue if its operand is an lvalue.  A simple
  820. assignment whose left-hand side is a cast works by converting the
  821. right-hand side first to the specified type, then to the type of the
  822. inner left-hand side expression.  After this is stored, the value is
  823. converted back to the specified type to become the value of the
  824. assignment.  Thus, if `a' has type `char *', the following two
  825. expressions are equivalent:
  826.  
  827.      (int)a = 5
  828.      (int)(a = (char *)(int)5)
  829.  
  830.    An assignment-with-arithmetic operation such as `+=' applied to a
  831. cast performs the arithmetic using the type resulting from the cast,
  832. and then continues as in the previous case.  Therefore, these two
  833. expressions are equivalent:
  834.  
  835.      (int)a += 5
  836.      (int)(a = (char *)(int) ((int)a + 5))
  837.  
  838.    You cannot take the address of an lvalue cast, because the use of its
  839. address would not work out coherently.  Suppose that `&(int)f' were
  840. permitted, where `f' has type `float'.  Then the following statement
  841. would try to store an integer bit-pattern where a floating point number
  842. belongs:
  843.  
  844.      *&(int)f = 1;
  845.  
  846.    This is quite different from what `(int)f = 1' would do--that would
  847. convert 1 to floating point and store it.  Rather than cause this
  848. inconsistency, we think it is better to prohibit use of `&' on a cast.
  849.  
  850.    If you really do want an `int *' pointer with the address of `f',
  851. you can simply write `(int *)&f'.
  852.  
  853. File: gcc.info,  Node: Conditionals,  Next: Long Long,  Prev: Lvalues,  Up: C Extensions
  854.  
  855. Conditionals with Omitted Operands
  856. ==================================
  857.  
  858.    The middle operand in a conditional expression may be omitted.  Then
  859. if the first operand is nonzero, its value is the value of the
  860. conditional expression.
  861.  
  862.    Therefore, the expression
  863.  
  864.      x ? : y
  865.  
  866. has the value of `x' if that is nonzero; otherwise, the value of `y'.
  867.  
  868.    This example is perfectly equivalent to
  869.  
  870.      x ? x : y
  871.  
  872. In this simple case, the ability to omit the middle operand is not
  873. especially useful.  When it becomes useful is when the first operand
  874. does, or may (if it is a macro argument), contain a side effect.  Then
  875. repeating the operand in the middle would perform the side effect
  876. twice.  Omitting the middle operand uses the value already computed
  877. without the undesirable effects of recomputing it.
  878.  
  879. File: gcc.info,  Node: Long Long,  Next: Complex,  Prev: Conditionals,  Up: C Extensions
  880.  
  881. Double-Word Integers
  882. ====================
  883.  
  884.    GNU C supports data types for integers that are twice as long as
  885. `long int'.  Simply write `long long int' for a signed integer, or
  886. `unsigned long long int' for an unsigned integer.  To make an integer
  887. constant of type `long long int', add the suffix `LL' to the integer.
  888. To make an integer constant of type `unsigned long long int', add the
  889. suffix `ULL' to the integer.
  890.  
  891.    You can use these types in arithmetic like any other integer types.
  892. Addition, subtraction, and bitwise boolean operations on these types
  893. are open-coded on all types of machines.  Multiplication is open-coded
  894. if the machine supports fullword-to-doubleword a widening multiply
  895. instruction.  Division and shifts are open-coded only on machines that
  896. provide special support.  The operations that are not open-coded use
  897. special library routines that come with GNU CC.
  898.  
  899.    There may be pitfalls when you use `long long' types for function
  900. arguments, unless you declare function prototypes.  If a function
  901. expects type `int' for its argument, and you pass a value of type `long
  902. long int', confusion will result because the caller and the subroutine
  903. will disagree about the number of bytes for the argument.  Likewise, if
  904. the function expects `long long int' and you pass `int'.  The best way
  905. to avoid such problems is to use prototypes.
  906.  
  907. File: gcc.info,  Node: Complex,  Next: Zero Length,  Prev: Long Long,  Up: C Extensions
  908.  
  909. Complex Numbers
  910. ===============
  911.  
  912.    GNU C supports complex data types.  You can declare both complex
  913. integer types and complex floating types, using the keyword
  914. `__complex__'.
  915.  
  916.    For example, `__complex__ double x;' declares `x' as a variable
  917. whose real part and imaginary part are both of type `double'.
  918. `__complex__ short int y;' declares `y' to have real and imaginary
  919. parts of type `short int'; this is not likely to be useful, but it
  920. shows that the set of complex types is complete.
  921.  
  922.    To write a constant with a complex data type, use the suffix `i' or
  923. `j' (either one; they are equivalent).  For example, `2.5fi' has type
  924. `__complex__ float' and `3i' has type `__complex__ int'.  Such a
  925. constant always has a pure imaginary value, but you can form any
  926. complex value you like by adding one to a real constant.
  927.  
  928.    To extract the real part of a complex-valued expression EXP, write
  929. `__real__ EXP'.  Likewise, use `__imag__' to extract the imaginary part.
  930.  
  931.    The operator `~' performs complex conjugation when used on a value
  932. with a complex type.
  933.  
  934.    GNU CC can allocate complex automatic variables in a noncontiguous
  935. fashion; it's even possible for the real part to be in a register while
  936. the imaginary part is on the stack (or vice-versa).  None of the
  937. supported debugging info formats has a way to represent noncontiguous
  938. allocation like this, so GNU CC describes a noncontiguous complex
  939. variable as if it were two separate variables of noncomplex type.  If
  940. the variable's actual name is `foo', the two fictitious variables are
  941. named `foo$real' and `foo$imag'.  You can examine and set these two
  942. fictitious variables with your debugger.
  943.  
  944.    A future version of GDB will know how to recognize such pairs and
  945. treat them as a single variable with a complex type.
  946.  
  947. File: gcc.info,  Node: Zero Length,  Next: Variable Length,  Prev: Complex,  Up: C Extensions
  948.  
  949. Arrays of Length Zero
  950. =====================
  951.  
  952.    Zero-length arrays are allowed in GNU C.  They are very useful as
  953. the last element of a structure which is really a header for a
  954. variable-length object:
  955.  
  956.      struct line {
  957.        int length;
  958.        char contents[0];
  959.      };
  960.      
  961.      {
  962.        struct line *thisline = (struct line *)
  963.          malloc (sizeof (struct line) + this_length);
  964.        thisline->length = this_length;
  965.      }
  966.  
  967.    In standard C, you would have to give `contents' a length of 1, which
  968. means either you waste space or complicate the argument to `malloc'.
  969.  
  970. File: gcc.info,  Node: Variable Length,  Next: Macro Varargs,  Prev: Zero Length,  Up: C Extensions
  971.  
  972. Arrays of Variable Length
  973. =========================
  974.  
  975.    Variable-length automatic arrays are allowed in GNU C.  These arrays
  976. are declared like any other automatic arrays, but with a length that is
  977. not a constant expression.  The storage is allocated at the point of
  978. declaration and deallocated when the brace-level is exited.  For
  979. example:
  980.  
  981.      FILE *
  982.      concat_fopen (char *s1, char *s2, char *mode)
  983.      {
  984.        char str[strlen (s1) + strlen (s2) + 1];
  985.        strcpy (str, s1);
  986.        strcat (str, s2);
  987.        return fopen (str, mode);
  988.      }
  989.  
  990.    Jumping or breaking out of the scope of the array name deallocates
  991. the storage.  Jumping into the scope is not allowed; you get an error
  992. message for it.
  993.  
  994.    You can use the function `alloca' to get an effect much like
  995. variable-length arrays.  The function `alloca' is available in many
  996. other C implementations (but not in all).  On the other hand,
  997. variable-length arrays are more elegant.
  998.  
  999.    There are other differences between these two methods.  Space
  1000. allocated with `alloca' exists until the containing *function* returns.
  1001. The space for a variable-length array is deallocated as soon as the
  1002. array name's scope ends.  (If you use both variable-length arrays and
  1003. `alloca' in the same function, deallocation of a variable-length array
  1004. will also deallocate anything more recently allocated with `alloca'.)
  1005.  
  1006.    You can also use variable-length arrays as arguments to functions:
  1007.  
  1008.      struct entry
  1009.      tester (int len, char data[len][len])
  1010.      {
  1011.        ...
  1012.      }
  1013.  
  1014.    The length of an array is computed once when the storage is allocated
  1015. and is remembered for the scope of the array in case you access it with
  1016. `sizeof'.
  1017.  
  1018.    If you want to pass the array first and the length afterward, you can
  1019. use a forward declaration in the parameter list--another GNU extension.
  1020.  
  1021.      struct entry
  1022.      tester (int len; char data[len][len], int len)
  1023.      {
  1024.        ...
  1025.      }
  1026.  
  1027.    The `int len' before the semicolon is a "parameter forward
  1028. declaration", and it serves the purpose of making the name `len' known
  1029. when the declaration of `data' is parsed.
  1030.  
  1031.    You can write any number of such parameter forward declarations in
  1032. the parameter list.  They can be separated by commas or semicolons, but
  1033. the last one must end with a semicolon, which is followed by the "real"
  1034. parameter declarations.  Each forward declaration must match a "real"
  1035. declaration in parameter name and data type.
  1036.  
  1037. File: gcc.info,  Node: Macro Varargs,  Next: Subscripting,  Prev: Variable Length,  Up: C Extensions
  1038.  
  1039. Macros with Variable Numbers of Arguments
  1040. =========================================
  1041.  
  1042.    In GNU C, a macro can accept a variable number of arguments, much as
  1043. a function can.  The syntax for defining the macro looks much like that
  1044. used for a function.  Here is an example:
  1045.  
  1046.      #define eprintf(format, args...)  \
  1047.       fprintf (stderr, format , ## args)
  1048.  
  1049.    Here `args' is a "rest argument": it takes in zero or more
  1050. arguments, as many as the call contains.  All of them plus the commas
  1051. between them form the value of `args', which is substituted into the
  1052. macro body where `args' is used.  Thus, we have this expansion:
  1053.  
  1054.      eprintf ("%s:%d: ", input_file_name, line_number)
  1055.      ==>
  1056.      fprintf (stderr, "%s:%d: " , input_file_name, line_number)
  1057.  
  1058. Note that the comma after the string constant comes from the definition
  1059. of `eprintf', whereas the last comma comes from the value of `args'.
  1060.  
  1061.    The reason for using `##' is to handle the case when `args' matches
  1062. no arguments at all.  In this case, `args' has an empty value.  In this
  1063. case, the second comma in the definition becomes an embarrassment: if
  1064. it got through to the expansion of the macro, we would get something
  1065. like this:
  1066.  
  1067.      fprintf (stderr, "success!\n" , )
  1068.  
  1069. which is invalid C syntax.  `##' gets rid of the comma, so we get the
  1070. following instead:
  1071.  
  1072.      fprintf (stderr, "success!\n")
  1073.  
  1074.    This is a special feature of the GNU C preprocessor: `##' before a
  1075. rest argument that is empty discards the preceding sequence of
  1076. non-whitespace characters from the macro definition.  (If another macro
  1077. argument precedes, none of it is discarded.)
  1078.  
  1079.    It might be better to discard the last preprocessor token instead of
  1080. the last preceding sequence of non-whitespace characters; in fact, we
  1081. may someday change this feature to do so.  We advise you to write the
  1082. macro definition so that the preceding sequence of non-whitespace
  1083. characters is just a single token, so that the meaning will not change
  1084. if we change the definition of this feature.
  1085.  
  1086. File: gcc.info,  Node: Subscripting,  Next: Pointer Arith,  Prev: Macro Varargs,  Up: C Extensions
  1087.  
  1088. Non-Lvalue Arrays May Have Subscripts
  1089. =====================================
  1090.  
  1091.    Subscripting is allowed on arrays that are not lvalues, even though
  1092. the unary `&' operator is not.  For example, this is valid in GNU C
  1093. though not valid in other C dialects:
  1094.  
  1095.      struct foo {int a[4];};
  1096.      
  1097.      struct foo f();
  1098.      
  1099.      bar (int index)
  1100.      {
  1101.        return f().a[index];
  1102.      }
  1103.  
  1104. File: gcc.info,  Node: Pointer Arith,  Next: Initializers,  Prev: Subscripting,  Up: C Extensions
  1105.  
  1106. Arithmetic on `void'- and Function-Pointers
  1107. ===========================================
  1108.  
  1109.    In GNU C, addition and subtraction operations are supported on
  1110. pointers to `void' and on pointers to functions.  This is done by
  1111. treating the size of a `void' or of a function as 1.
  1112.  
  1113.    A consequence of this is that `sizeof' is also allowed on `void' and
  1114. on function types, and returns 1.
  1115.  
  1116.    The option `-Wpointer-arith' requests a warning if these extensions
  1117. are used.
  1118.  
  1119. File: gcc.info,  Node: Initializers,  Next: Constructors,  Prev: Pointer Arith,  Up: C Extensions
  1120.  
  1121. Non-Constant Initializers
  1122. =========================
  1123.  
  1124.    The elements of an aggregate initializer for an automatic variable
  1125. are not required to be constant expressions in GNU C.  Here is an
  1126. example of an initializer with run-time varying elements:
  1127.  
  1128.      foo (float f, float g)
  1129.      {
  1130.        float beat_freqs[2] = { f-g, f+g };
  1131.        ...
  1132.      }
  1133.  
  1134. File: gcc.info,  Node: Constructors,  Next: Labeled Elements,  Prev: Initializers,  Up: C Extensions
  1135.  
  1136. Constructor Expressions
  1137. =======================
  1138.  
  1139.    GNU C supports constructor expressions.  A constructor looks like a
  1140. cast containing an initializer.  Its value is an object of the type
  1141. specified in the cast, containing the elements specified in the
  1142. initializer.
  1143.  
  1144.    Usually, the specified type is a structure.  Assume that `struct
  1145. foo' and `structure' are declared as shown:
  1146.  
  1147.      struct foo {int a; char b[2];} structure;
  1148.  
  1149. Here is an example of constructing a `struct foo' with a constructor:
  1150.  
  1151.      structure = ((struct foo) {x + y, 'a', 0});
  1152.  
  1153. This is equivalent to writing the following:
  1154.  
  1155.      {
  1156.        struct foo temp = {x + y, 'a', 0};
  1157.        structure = temp;
  1158.      }
  1159.  
  1160.    You can also construct an array.  If all the elements of the
  1161. constructor are (made up of) simple constant expressions, suitable for
  1162. use in initializers, then the constructor is an lvalue and can be
  1163. coerced to a pointer to its first element, as shown here:
  1164.  
  1165.      char **foo = (char *[]) { "x", "y", "z" };
  1166.  
  1167.    Array constructors whose elements are not simple constants are not
  1168. very useful, because the constructor is not an lvalue.  There are only
  1169. two valid ways to use it: to subscript it, or initialize an array
  1170. variable with it.  The former is probably slower than a `switch'
  1171. statement, while the latter does the same thing an ordinary C
  1172. initializer would do.  Here is an example of subscripting an array
  1173. constructor:
  1174.  
  1175.      output = ((int[]) { 2, x, 28 }) [input];
  1176.  
  1177.    Constructor expressions for scalar types and union types are is also
  1178. allowed, but then the constructor expression is equivalent to a cast.
  1179.  
  1180. File: gcc.info,  Node: Labeled Elements,  Next: Cast to Union,  Prev: Constructors,  Up: C Extensions
  1181.  
  1182. Labeled Elements in Initializers
  1183. ================================
  1184.  
  1185.    Standard C requires the elements of an initializer to appear in a
  1186. fixed order, the same as the order of the elements in the array or
  1187. structure being initialized.
  1188.  
  1189.    In GNU C you can give the elements in any order, specifying the array
  1190. indices or structure field names they apply to.
  1191.  
  1192.    To specify an array index, write `[INDEX]' or `[INDEX] =' before the
  1193. element value.  For example,
  1194.  
  1195.      int a[6] = { [4] 29, [2] = 15 };
  1196.  
  1197. is equivalent to
  1198.  
  1199.      int a[6] = { 0, 0, 15, 0, 29, 0 };
  1200.  
  1201. The index values must be constant expressions, even if the array being
  1202. initialized is automatic.
  1203.  
  1204.    To initialize a range of elements to the same value, write `[FIRST
  1205. ... LAST] = VALUE'.  For example,
  1206.  
  1207.      int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };
  1208.  
  1209. Note that the length of the array is the highest value specified plus
  1210. one.
  1211.  
  1212.    In a structure initializer, specify the name of a field to initialize
  1213. with `FIELDNAME:' before the element value.  For example, given the
  1214. following structure,
  1215.  
  1216.      struct point { int x, y; };
  1217.  
  1218. the following initialization
  1219.  
  1220.      struct point p = { y: yvalue, x: xvalue };
  1221.  
  1222. is equivalent to
  1223.  
  1224.      struct point p = { xvalue, yvalue };
  1225.  
  1226.    Another syntax which has the same meaning is `.FIELDNAME ='., as
  1227. shown here:
  1228.  
  1229.      struct point p = { .y = yvalue, .x = xvalue };
  1230.  
  1231.    You can also use an element label (with either the colon syntax or
  1232. the period-equal syntax) when initializing a union, to specify which
  1233. element of the union should be used.  For example,
  1234.  
  1235.      union foo { int i; double d; };
  1236.      
  1237.      union foo f = { d: 4 };
  1238.  
  1239. will convert 4 to a `double' to store it in the union using the second
  1240. element.  By contrast, casting 4 to type `union foo' would store it
  1241. into the union as the integer `i', since it is an integer.  (*Note Cast
  1242. to Union::.)
  1243.  
  1244.    You can combine this technique of naming elements with ordinary C
  1245. initialization of successive elements.  Each initializer element that
  1246. does not have a label applies to the next consecutive element of the
  1247. array or structure.  For example,
  1248.  
  1249.      int a[6] = { [1] = v1, v2, [4] = v4 };
  1250.  
  1251. is equivalent to
  1252.  
  1253.      int a[6] = { 0, v1, v2, 0, v4, 0 };
  1254.  
  1255.    Labeling the elements of an array initializer is especially useful
  1256. when the indices are characters or belong to an `enum' type.  For
  1257. example:
  1258.  
  1259.      int whitespace[256]
  1260.        = { [' '] = 1, ['\t'] = 1, ['\h'] = 1,
  1261.            ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 };
  1262.  
  1263.